﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RegistrationController;

namespace HPMDesktop.Patient
{
    public partial class frmSelectPackage : Form
    {
        private Form _objParentForm;
        private string _parentClass;
        private Hashtable _packageInfo;

        public frmSelectPackage(Form objParentForm, string parentClass)
        {
            InitializeComponent();
            _objParentForm = objParentForm;
            _parentClass = parentClass;
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {
            if (_parentClass.Equals("frmRegistration"))
            {
                frmRegistration frm = (frmRegistration)_objParentForm;
                frm.setPackageDetails(cmbPackages.Text, txtPackageAmount.Text);
            }
            else if (_parentClass.Equals("frmShiftOutPatient"))
            {
                frmShiftOutPatient frm = (frmShiftOutPatient)_objParentForm;
                frm.setPackageDetails(cmbPackages.Text, txtPackageAmount.Text);
            }
            this.Close();
        }

        private void frmSelectPackage_Load(object sender, EventArgs e)
        {
            /* Load packages from db */
            Package_DataLoader objPkgDataLoader = new Package_DataLoader();

            _packageInfo = objPkgDataLoader.Get_Package_Data();

            foreach (String packageName in _packageInfo.Keys)
            {
                cmbPackages.Items.Add(packageName);
            }

            objPkgDataLoader.Dispose();
        }

        private void cmbPackages_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPackages.Text != "")
            {
                string packageName = cmbPackages.Text;
                txtPackageAmount.Text = _packageInfo[packageName].ToString();
            }
        }
    }
}
